package com.mojo.config;

import com.mojo.quartz.QuartzDemo;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/3/11 14:46
 */
@Configuration
public class QuartzConfig {
    @Bean("quartzDemo")
    public JobDetail quartzDemo() {
        return JobBuilder.newJob(QuartzDemo.class)
                .withIdentity("my quartz")
                .usingJobData("msg", "quartz job")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger jobTrigger() {
        CronScheduleBuilder schedule = CronScheduleBuilder.cronSchedule("0/5 * * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(quartzDemo())
                .withSchedule(schedule)
                .build();
    }
}
